package xyz.ddlnt.servicemq.listener;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import xyz.ddlnt.servicemq.service.PostService;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/9 19:06
 */
@Slf4j
@Component
public class PostListener {
    @Resource
    private PostService postService;

    /**
     * 帖子收藏数加1
     * @param postId
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "collect_count_plus_one"),
            exchange = @Exchange(name =  "usr.post"),
            key = "collect_count_plus_one"
    ))
    public void collectCountPlusOne(Long postId) {
        postService.collectCountPlusOne(postId);
        log.info("帖子收藏数加1");
    }

    /**
     * 帖子收藏数减1
     * @param postId
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "collect_count_minus_one"),
            exchange = @Exchange(name =  "usr.post"),
            key = "collect_count_minus_one"
    ))
    public void collectCountMinusOne(Long postId) {
        postService.collectCountMinusOne(postId);
        log.info("帖子收藏数减1");
    }

}
